﻿using Microsoft.AspNetCore.Authorization;
using Simple.Repository.Models;
using Simple.Services.System;

namespace Simple.WebApi.Controllers.System
{
    /// <summary>
    /// 幼儿考勤
    /// </summary>
    [Route("api/ChildAttendance/[action]")]
    [ApiController]
    [Authorize]
    public class ChildAttendanceController : ControllerBase
    {
        private readonly ChildAttendanceService _childAttendanceService;

        public ChildAttendanceController(ChildAttendanceService childAttendanceService)
        {
            _childAttendanceService = childAttendanceService;
        }

        /// <summary>
        /// 幼儿考勤记录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> Page([FromQuery] ChildAttendancePageInputModel model)
        {
            PageResultModel<ChildAttendanceModel> data = await _childAttendanceService.GetPageAsync(model);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 考勤详情
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> Detail([FromQuery] DetailInput model)
        {
            List<ChildAttendanceDetailDto> data = await _childAttendanceService.GetDetailAsync(model);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 幼儿考勤首页（园务端）
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> ChildAttendanceStats()
        {
            MobileChildAttendanceDto data = await _childAttendanceService.MobileChildAttendanceStats();
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 入园记录（家长端）
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> AdmissionRecord()
        {
            MobileAdmissionRecordDto data = await _childAttendanceService.MobileAdmissionRecord();
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 入园记录详情（家长端）
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> AdmissionRecordDetail([FromQuery] MobileChildAttendanceInput model)
        {
            List<MobileAdmissionRecordDetailDto> data = await _childAttendanceService.MobileAdmissionRecordDetail(model);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 已签到统计
        /// </summary>
        [HttpGet]
        public async Task<AppResult> CheckedStats([FromQuery] GetCheckedStatsInput model)
        {
            CheckedInDto data = await _childAttendanceService.GetCheckedStats(model);
            return AppResult.Status200OK(data: data); 
        }

        /// <summary>
        /// 未签到
        /// </summary>
        [HttpGet]
        public async Task<AppResult> NotCheckedStats([FromQuery] NotCheckedStatsInput model)
        {
            NotCheckedStatsDto data = await _childAttendanceService.GetNotCheckedStats(model);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 手动签到
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> ManualCheck([FromBody] ManualCheckInput model)
        {
            await _childAttendanceService.ManualCheck(model);
            return AppResult.Status200OK("新增成功");
        }



        /// <summary>
        /// 班级考勤记录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> GetClassAttendanceAsync([FromQuery] StudentAttendancePageInputModel model)
        {
            PageResultModel<StudentAttendanceModel> data = await _childAttendanceService.GetClassAttendanceAsync(model);
            return AppResult.Status200OK(data: data);
        }
    }
}
